/**
 * Created by cwfan on 2015/6/29.
 *
 * var logger = new Logger();
 * var logger = new Logger('email');
 * var logger = new Logger('app',Logger.Level.ERROR);
 */

var log4js = require('log4js'),
    fs = require('fs'),
    path = require('path');
var LOG_DIR = "logs/";

log4js.configure({
    appenders: [{
        type: 'console'
    }, {
        filename: LOG_DIR + '/log',
        maxLogSize: 1024 * 10, //10 MB
        backups: 10,
        pattern: "-yyyy-MM-dd.log",
        alwaysIncludePattern: true,
        type: 'dateFile'
    }, {
        "type": "logLevelFilter",
        "level": "ERROR",
        "appender": {
            filename: LOG_DIR + '/err',
            maxLogSize: 1024 * 10, //10 MB
            backups: 10,
            pattern: "-yyyy-MM-dd.log",
            alwaysIncludePattern: true,
            type: 'dateFile'
        }
    }],
    levels: {
        "App": "info",
        "FileProcessList": "info",
        "LogAPIRouter": "info",
        "AppInfoManager": "info",
        "LogItemManger": "info",
        "LogItemDao": "info",
        "AppInfoDao": "info",
        "MongoDB": "info",
        "FileProcessList": "info",
        "[all]": 'ERROR'
    },
    //replaceConsole: false
});
//全局设置
var Logger = function(module, level) {
    module = module || 'system';
    var logger = log4js.getLogger(module);
    if (level) logger.setLevel(level);
    return logger;
}

Logger.Level = {
    all: 'ALL',
    trace: 'TRACE',
    debug: 'DEBUG',
    info: 'INFO',
    warn: 'WARN',
    error: 'ERROR',
    fatal: 'FATAL',
    off: 'OFF'
}

log4js.setGlobalLogLevel(Logger.Level.warn); //全局的

module.exports = Logger;
